﻿
#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Windows.Resources;

#endregion

namespace FasterWPF
{
    public class MenuItemArgs
    {
       // public int PageNum { get; set; }
    }

    public class MenuItemParent : FasterWPF.IParent 
    {         
        //this is ANA?
        public object Generate<T>(object chain, T args, Action<ContentControl> addUIElementsAction)
        {
            return chain;
        }

        //this is BIND
        public object Add<T>(object chain, string key, T args, Border itemToAdd)
        {
            MenuItem menuItm = itemToAdd.Child.Cast<ContentControl>().GetElement<MenuItem, MenuItem>(0, 0);

            ((MenuItem)chain).GetSetting<MenuItem, ObservableCollection<MenuItem>>("ObsCol").Add(menuItm);

        //    if (args is MenuArgs)
        //    {
        //        ((Menu)chain).Items.Add(menuItm);
       //     }

            var collection = ((MenuItem)chain).GetSetting<MenuItem, ObservableCollection<MenuItem>>("ObsCol");
            if (((MenuItem)chain).ItemsSource != collection)
            {
                ((MenuItem)chain).ItemsSource = collection;
            }

            return chain;
        }

        public void Remove(object chain, string key, Border itemToRemove)
        {
            MenuItem menuItm = itemToRemove.Child.Cast<ContentControl>().GetElement<MenuItem, MenuItem>(0, 0);

            ((MenuItem)chain).GetSetting<MenuItem, ObservableCollection<MenuItem>>("ObsCol").Remove(menuItm);

            IComposite ic = (IComposite)(((MenuItem)chain).GetIComposite<MenuItem>());
            ic.RemoveFromChain(itemToRemove);
        }

        public Dictionary<string, object> RetrieveDictionary(object chain)
        {
            return ((MenuItem)chain).GetCompositeLookupDictionary<MenuItem>();
        }

        //this is CATA?
        public List<Border> RetrieveCollection(object chain)
        {
            List<Border> lb = new List<Border>();
            foreach (var kvp in ((MenuItem)chain).GetCompositeLookupDictionary<MenuItem>())
            {
                lb.Add((Border)kvp.Value);
            }

            return lb;
        }

        public void ClearCollection(object chain)
        {
        }

        public void BeforeSortCollection<T>(object chain, object args, int row, int column, FasterWPF.CommonExt.SortOrder sortOrder)
                  where T : FrameworkElement
        { }

        public void BeforeSortCollection1Then2<T>(object chain, object args, int row, int column, int row2, int column2, FasterWPF.CommonExt.SortOrder sortOrder, FasterWPF.CommonExt.SortOrder sortOrder2)
  where T : FrameworkElement
        { }
        
        public void AfterSortCollection<T>(object chain)
             where T : FrameworkElement
        { }

        public void InnerSortCollection(object chain, int row, int column, string key, ref int counter, Border itemToReAdd)
        {
            throw new NotImplementedException();
        }
        
        public void SetSelected(object chain, Border itemToSetAsSelected)
        {
        }

        //public void GetSelected
        //    return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);

    }
}
